﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MobileSales.Model.Params;
using System.Runtime.Serialization;
using System.ComponentModel.DataAnnotations;
using MobileSales.Model.Localization;
using MobileSales.Model.Util;

namespace MobileSales.Model.Products
{
    [DataContract]
    public class Product : ParamObject
    {
        #region Private members
        private IList<ProductImage> _images;
        private IList<Category> _categories;
        #endregion

        #region Public members
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Sku", ResourceType = typeof(ModelStrings))]
        public string Sku { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Name", ResourceType = typeof(ModelStrings))]
        public string Name { get; set; }
        [DataMember]
        [Display(Name = "Description", ResourceType = typeof(ModelStrings))]
        public string Description { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Price", ResourceType = typeof(ModelStrings))]
        [RegularExpression(RegExp.DoubleRegexp, ErrorMessageResourceName = "InvalidDouble", ErrorMessageResourceType = typeof(ValidationStrings))]
        public double Price { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Quantity", ResourceType = typeof(ModelStrings))]
        [RegularExpression(RegExp.DoubleRegexp, ErrorMessageResourceName = "InvalidDouble", ErrorMessageResourceType = typeof(ValidationStrings))]
        public double Quantity { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "MinQuantity", ResourceType = typeof(ModelStrings))]
        [RegularExpression(RegExp.DoubleRegexp, ErrorMessageResourceName = "InvalidDouble", ErrorMessageResourceType = typeof(ValidationStrings))]
        public double MinQuantity { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "OrderQuantity", ResourceType = typeof(ModelStrings))]
        [RegularExpression(RegExp.DoubleRegexp, ErrorMessageResourceName = "InvalidDouble", ErrorMessageResourceType = typeof(ValidationStrings))]
        public double OrderQuantity { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [RegularExpression(RegExp.DoubleRegexp, ErrorMessageResourceName = "InvalidDouble", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Spread", ResourceType = typeof(ModelStrings))]
        public double Spread { get; set; }
        [DataMember]
        [Display(Name = "Symbol", ResourceType = typeof(ModelStrings))]
        public string Symbol { get; set; }
        [DataMember]
        [Display(Name = "IsMarketingOnlyItem", ResourceType = typeof(ModelStrings))]
        public bool IsMarketingOnlyItem { get; set; }
        [DataMember]
        public Tax Tax { get; set; }
        [DataMember]
        [Display(Name = "Tax", ResourceType = typeof(ModelStrings))]
        public int TaxId { get; set; }
        [DataMember]
        public Unit Unit { get; set; }
        [DataMember]
        [Display(Name = "Unit", ResourceType = typeof(ModelStrings))]
        public int UnitId { get; set; }
        [DataMember]
        public IList<ProductImage> Images
        {
            get { return _images; }
            set { _images = value; }
        }
        [DataMember]
        public IList<Category> Categories
        {
            get { return _categories; }
            set { _categories = value; }
        }
        #endregion

        #region Constructor

        public Product()
            : base()
        {
            _images = new List<ProductImage>();
        }

        #endregion
    }
}
